package com.zhang.bingmei_incomeexpenditure.service.factory;

import com.zhang.bingmei_incomeexpenditure.service.strategy.DataScopeStrategy;
import com.zhang.bingmei_incomeexpenditure.service.strategy.Impl.AdminProvinceDataScopeStrategy;
import com.zhang.bingmei_incomeexpenditure.service.strategy.Impl.CityDataScopeStrategy;
import com.zhang.bingmei_incomeexpenditure.service.strategy.Impl.DistrictDataScopeStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据权限策略工厂：根据角色等级获取对应策略
 */
public class DataScopeStrategyFactory {
    private static final Map<Integer, DataScopeStrategy> STRATEGY_MAP = new HashMap<>();

    // 静态初始化策略
    static {
        STRATEGY_MAP.put(1, new AdminProvinceDataScopeStrategy());
        STRATEGY_MAP.put(2, new AdminProvinceDataScopeStrategy()); // 角色2复用角色1策略
        STRATEGY_MAP.put(3, new CityDataScopeStrategy());
        STRATEGY_MAP.put(4, new DistrictDataScopeStrategy());
    }

    /**
     * 根据角色等级获取策略
     */
    public static DataScopeStrategy getStrategy(int roleLevel) {
        DataScopeStrategy strategy = STRATEGY_MAP.get(roleLevel);
        if (strategy == null) {
            throw new RuntimeException("不支持的角色等级：" + roleLevel);
        }
        return strategy;
    }
}